#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > ccsdr12_h2o_gamma.info <<'%EOF%'
   ccsdr12_h2o_gamma
   -------------
   Molecule:         H2O
   Wave Functions:   CCSD(R12)/B 6-311G/6-311++G** 
   Test Purpose:     Check properties up to cubic response
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > ccsdr12_h2o_gamma.mol <<'%EOF%'
BASIS
6-311G 6-311++G**
H2O with symmetry

    4    2 X Z
 1      8.    1
O     0.0 -0.2249058930 0.0
 1      1.    1
H     1.45235 0.899623 0.0
 2      8.    1
O     0.0 -0.2249058930 0.0
 2      1.    1
H     1.45235 0.899623 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > ccsdr12_h2o_gamma.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
*MOLBAS
.R12AUX
**INTEGRALS
.R12
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT
.THRESHOLD
 1D-10
*ORBITALS
.R12ORB
 1 0 0 0 
.MOSTART
 H1DIAG
*CC INPUT
.CCSD
.PRINT
 3
.FREEZE
  1 0 
.THRENR
 1.0D-13
.THRLEQ
 1.0D-12
*CCFOP
.NONREL
.DIPMOM
*CCLR
.DIPOLE
*CCQR
.DIPOLE
*CCCR
.DIPOLE
*R12 INPUT
.NO HYB
.CC2
 1B
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >ccsdr12_h2o_gamma.check
cat >>ccsdr12_h2o_gamma.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#
#            Total SCF   energy:                   -76.0085552989
#            Total MP2-R12/B energy:               -76.2460725378
#            Total CCSD(R12)/B energy:             -76.2428193358
#
#
CRIT1=`$GREP "Total MP2-R12/B energy: *-76\.2460725378" $log | wc -l`
TEST[1]=`expr   $CRIT1`
CTRL[1]=2
ERROR[1]="MP2-R12/B ENERGY NOT CORRECT"
CRIT2=`$GREP "Total CCSD\(R12\)/B energy: *-76.2428193358" $log | wc -l`
TEST[2]=`expr   $CRIT2`
CTRL[2]=2
ERROR[2]="CCSD(R12) ENERGY NOT CORRECT"
#
CRIT3=`$GREP "y *1.03602830 *2.63332110" $log | wc -l`
TEST[3]=`expr $CRIT3`
CTRL[3]=1
ERROR[3]="CCSD(R12) DIPOLE MOMENT NOT CORRECT"

CRIT4=`$GREP "XDIPLEN .*7\.2178740" $log | wc -l`
CRIT5=`$GREP "YDIPLEN .*4\.9966026" $log | wc -l`
CRIT6=`$GREP "ZDIPLEN .*2\.6061576" $log | wc -l`
TEST[4]=`expr $CRIT4 + $CRIT5 + $CRIT6`
CTRL[4]=3
ERROR[4]="CCSD(R12) POLARZABILITY NOT CORRECT"

CRIT7=`$GREP "XDIPLEN .*\-20\.202442" $log | wc -l`
CRIT8=`$GREP "YDIPLEN .*\-17\.679405" $log | wc -l`
CRIT9=`$GREP "ZDIPLEN .*\-4\.9860487" $log | wc -l`
TEST[5]=`expr $CRIT7 + $CRIT8 + $CRIT9`
CTRL[5]=7
ERROR[5]="CCSD(R12) FIRST HYPERPOLARIZABILITY NOT CORRECT"

CRIT10=`$GREP "XDIPLEN .*\-214\.59117" $log | wc -l`
CRIT11=`$GREP "XDIPLEN .*\-197\.74352" $log | wc -l`
CRIT12=`$GREP "XDIPLEN .*\-58\.175863" $log | wc -l`
CRIT13=`$GREP "YDIPLEN .*\-201\.28301" $log | wc -l`
CRIT14=`$GREP "YDIPLEN .*\-43\.156266" $log | wc -l`
CRIT15=`$GREP "ZDIPLEN .*\-18\.799083" $log | wc -l`
TEST[6]=`expr $CRIT10 + $CRIT11 + $CRIT12 + $CRIT13 + $CRIT14 + $CRIT15`
CTRL[6]=21
ERROR[6]="CCSD(R12) SECOND HYPERPOLARIZABILITY NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
